﻿/*!
* jQuery grid plugin: 
* 
* version 0.1 2010-11-08
* Requires jQuery v1.4.2 or later
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* Authors: Kim Seoung Min
* Company : Kongyoung DB
*/
(function ($) {

    $.fn.SuperTable = function (method) {
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' + method + ' does not exist on jQuery.tooltip');
        }
    };

    var methods = {
        init: function (url) {
            JsonForm = GetJsonSync(url);
            var SuperTable = $(this);
            SuperTable.html("").addClass("SuperTable");
            var SuperTable_filter = $("<div  class='showFilterArea ui-state-default'><ul></ul></div>").appendTo(SuperTable);
            var SuperTable_head = $("<div  class='head'><div  class='SuperTable_head_L'></div><div  class='SuperTable_head_R'></div></div>").appendTo(SuperTable);
            var SuperTable_body = $("<table border='0' cellpadding='0' cellspacing='0' ><thead class='ui-widget-header'></thead><tbody class='ui-widget-content'></tbody></table>").appendTo(SuperTable);
            var SuperTable_foot = $("<div  class='foot'><div  class='SuperTable_head_L'></div><div  class='SuperTable_head_R'></div></div>").appendTo(SuperTable);
            ///////////////////////////////////////////////////////                        
            var chkclass = JsonForm.ShowRowSelect ? 'SuperTable_show_td' : 'SuperTable_hidn_td';
            var IDclass = JsonForm.ShowRowNum ? 'SuperTable_show_td' : 'SuperTable_hidn_td';
            var CRUDclass = JsonForm.ShowCRUD ? 'SuperTable_show_td' : 'SuperTable_hidn_td';
            var colCount = JsonForm.colModel.length;
            var rowNum = JsonForm.rowNum;
            var filterStr = "";
            var th = "<td class='" + chkclass + " tdCHK'> <input type='checkbox' class='ChkAll' value='checkAll' /></td>";
            var td = "<td class='" + chkclass + " tdCHK'> <input type='checkbox' value='check' /></td>";
            th += "<td class='" + IDclass + " tdID'>No</td>";
            td += "<td class='" + IDclass + " tdID'>&nbsp;</td>";
            th += "<td class='" + CRUDclass + " tdCURD'>CRUD</td>";
            td += "<td class='" + CRUDclass + " tdCURD'>&nbsp;</td>";

            /// : 초기테이블 해드와 row를 생성한다 ////////////////////////////////////////////
            for (var i = 0; i < colCount; i++) {
                var _index = JsonForm.colModel[i].index;
                var _width = JsonForm.colModel[i].width;
                var _caption = JsonForm.colModel[i].name;
                var _align = JsonForm.colModel[i].align;
                var _type = JsonForm.colModel[i].type;
                var _code = JsonForm.colModel[i].code;
                var _filter = JsonForm.colModel[i].filter;

                var _tdCss = JsonForm.colModel[i].type == "hidden" ? "SuperTable_hidn_td" : "SuperTable_show_td"; //"hidn_td":"show_td";
                var _style = " style='width: " + _width + ";text-align:" + _align + ";' class='" + _tdCss + "'  field='" + _index + "' ftype= '" + _type + "' code= '" + _type + "'  ";

                th += "<td class='" + _tdCss + "' field='" + _index + "' style='width: " + _width + "' >" + _caption + "</td>";
                var filterObj = "";
                switch (_type) {
                    case 'integer':
                        td += "<td " + _style + "><input type='text' class='gridTextNum' value='' oldvalue = ''/></td>";
                        break;
                    case 'string':
                        td += "<td " + _style + "><input type='text' class='gridTextBox' value='' oldvalue = ''/></td>";
                        break;
                    case 'combo':
                        // 콤보박스 바인딩처리용 옵션리스트를 미리 정의하여 저장하여 둔다
                        if (_code != undefined && _code != "" && _code != null) {
                            var pl = new JSONClientParameters();
                            pl.add("CODETY", _code);
                            var jdata = PostJsonSync("/bzService/superboard.asmx/GETCOMCODE", pl);
                            var selHtml = "";
                            $.each(jdata, function (index, value) {
                                selHtml += String.format("<option value='{0}'>{1}</option>", value.CodeID, value.CodeNAME);
                            });
                            td += "<td " + _style + "><select class='gridCombo' value='' oldvalue = ''>" + selHtml + "</select></td>";
                        }
                        break;
                    default:
                        td += "<td " + _style + ">&nbsp;</td>";
                        filterObj += "<li filter=\"" + _filter + "\"><span>" + _caption + ":</span><input  type='text' value='' /></li>";
                }

                if (_filter) filterStr += filterObj;
            }

            //// head 생성 ///////////////////////////////////////////////////////////////////////////////////////////////
            th = "<tr>" + th + "</tr>"; //-->> No 항목 + 설정된 항목 헤더 바인딩
            $('thead', SuperTable_body).html("").html(th);
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////

            ////// body 생성 /////////////////////////////////////////////////////////////////////////////////////////////
            td = "<tr>" + td + "</tr>";
            tb = "";
            for (var i = 0; i < rowNum; i++) { tb += td; }
            $('tbody', SuperTable_body).html("").html(th);


            //// filter 생성 ///////////////////////////////////////////////////////////////////////////////////////////////
            if (JsonForm.ShowFilter) {
                $('.showFilterArea ul', SuperTable).html("").html(filterStr);
            }
            else {
                $('.showFilterArea ul', SuperTable).toggle();
            }

            if (!JsonForm.ShowFilter) {
                $('.showFilterArea', SuperTable).hide();
            }
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////

            if (JsonForm.ShowJobBottom) {
                var jobCount = JsonForm.Jobs.length;
                /// : 초기테이블 해드와 row를 생성한다 ////////////////////////////////////////////
                var jobComm = "";
                for (var i = 0; i < jobCount; i++) {
                    var _index = JsonForm.Jobs[i].index;
                    var _name = JsonForm.Jobs[i].name;
                    var _icon = JsonForm.Jobs[i].icon;
                    jobComm += "<button class='cmdBtn' index='" + _index + "' icon='" + _icon + "'>" + _name + "</button>";
                }
                //jobComm += "</div>";
                $(this).find('.head .SuperTable_head_L').html(jobComm);
                $(this).find('.foot .SuperTable_head_L').html(jobComm);

                /* 테이블 잡 명령버턴에 대한 정의 */
                var _SuperTable = $(this);
                $(this).find('.SuperTable_head_L .cmdBtn').each(function (index) {
                    var icon = $(this).attr('icon');
                    $(this).button({ icons: { primary: icon} }).bind("click", function (e) {
                        if ($(this).attr('index') == "ShowFilterUrl") {
                            _SuperTable.SuperTable("ShowFilterUrl");
                        } else {
                            eval(JsonForm.jobCallBack)(e);
                        }
                    });
                });
            }

            if (!JsonForm.ShowJobBottom) {
                $(this).find('.head .SuperTable_head_L').hide();
                $(this).find('.foot .SuperTable_head_L').hide();
            }

            /////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // 제사용이 가능하도록 구조정보를 보관한다.
            $(this).data("formatData", JsonForm);
            $(this).data("TRdata", SuperTable_body.find('tbody tr:last'));
            SuperTable_body.find('tbody tr').remove();

            $(this).SuperTable("ShowFilterUrl");
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            return this;
        },

        ShowJsonUrl: function (url) {
            var _data = GetJsonSync(url);
            var _Obj = $(this);
            _Obj.SuperTable("ShowData", _data, 15, 1, 1);
        },

        ShowDataUrl: function (pl) {
            $(this).data("filter", pl);
            var JsonForm = $(this).data("formatData");
            pl.add("pagecnt", JsonForm.rowNum);
            pl.add("viewpage", 1);
            pl.add("OrderStr", JsonForm.Orderby);
            var loader = jQuery('<div><img src="/image/spinner.gif" /><br>Loading...</div>');
            var _Obj = $(this);
            _Obj.find('table tbody').hide();
            loader.prependTo(_Obj.find('table'));
            PostJsonData(JsonForm.ListUr, pl, function (data) {
                var _data = eval("data." + JsonForm.DataName);
                _Obj.SuperTable("ShowData", _data, data.TRCOUNT, data.VIEWPAGE, data.TPCOUNT);
                loader.remove();
                _Obj.find('table tbody').show();
                if (_Obj.find('tbody tr').length == 0) {
                    alert("검색조건에 해당되는 자료가 없습니다.");
                }
            });
        },

        ShowFilterUrl: function () {

            var filters = "";
            $(this).find('.showFilterArea ul li').each(function (index) {
                var filter = $(this).attr("filter");
                var Data = $(this).find("input").val();
                if (Data != "") {
                    if (filters != "") filters += " AND ";
                    filters += filter.replace('{0}', Data);
                }
            });


            $(this).data("filter", filters);

            var _Obj = $(this);
            var _datatable = $('tbody', $(this));
            var JsonForm = $(this).data("formatData");
            var pl = new JSONClientParameters();
            pl.add("filter", filters);
            pl.add("pagecnt", JsonForm.rowNum);
            pl.add("viewpage", "1");
            pl.add("OrderStr", JsonForm.Orderby);

            var loader = jQuery('<div class="loader"><img src="/image/spinner.gif" /><br>Loading...</div>');
            var _Obj = $(this);
            //_Obj.find('table tbody').hide();
            loader.prependTo(_Obj);
            PostJsonData(JsonForm.FilterListUrl, pl, function (data) {
                try {
                    var _data = eval("data." + JsonForm.DataName);
                    _Obj.SuperTable("ShowData", _data, data.TRCOUNT, data.VIEWPAGE, data.TPCOUNT);
                    loader.remove();

                    //_Obj.find('table tbody').show();
                    if (_data.length == 0) {
                        alert("검색조건에 해당되는 자료가 없습니다.");
                    }
                }
                catch (e1) {
                    alert(e1.message);
                }
            });
            // }
        },


        ShowPage: function (page) {
            var _Obj = $(this);
            var _datatable = $('tbody', $(this));
            var JsonForm = $(this).data("formatData");
            var pl = new JSONClientParameters();

            if ($(this).data("filter") != undefined) {
                pl.add("filter", $(this).data("filter"));
            }

            pl.add("pagecnt", JsonForm.rowNum);
            pl.add("viewpage", page);
            pl.add("OrderStr", JsonForm.Orderby);

            var loader = jQuery('<div class="loader"><img src="/image/spinner.gif" /><br>Loading...</div>');
            var _Obj = $(this);
            //_Obj.find('table tbody').hide();
            loader.prependTo(_Obj);
            PostJsonData(JsonForm.FilterListUrl, pl, function (data) {
                var _data = eval("data." + JsonForm.DataName);
                _Obj.SuperTable("ShowData", _data, data.TRCOUNT, data.VIEWPAGE, data.TPCOUNT);
                loader.remove();
                //_Obj.find('table tbody').show();
                if (_Obj.find('tbody tr').length == 0) {
                    alert("검색조건에 해당되는 자료가 없습니다.");
                }
            });
        },

        SortPage: function (SortField) {
            var JsonForm = $(this).data("formatData");

            var _var = JsonForm.Orderby.split(' ');
            if (SortField == _var[0]) {
                JsonForm.Orderby = SortField + (_var[1] == "ASC" ? " DESC" : " ASC");
            }
            else {
                JsonForm.Orderby = SortField + " ASC";
            }

            $(this).data("formatData", JsonForm);
            this.SuperTable("ShowPage", 1);
        },

        ShowData: function (JsonData, TRCOUNT, VIEWPAGE, TPCOUNT) {

            this.SuperTable("ClearData");
            var JsonForm = $(this).data("formatData");
            var rowNum = JsonForm.rowNum;
            var TrData = $(this).data("TRdata");
            var Rows = JsonData.length;
            if (Rows == 0) { return 0; }

            for (var i = 0; i < Rows; i++) {
                var DataRow = JsonData[i];
                var td = "";
                var newTr = TrData.clone();
                newTr.attr("key", DataRow[JsonForm.keyname]);
                newTr.find('td').each(function (index) {
                    if (index == 0) return true; //continue;

                    var _ftype = $(this).attr('ftype');
                    var _field = $(this).attr('field');
                    var _code = $(this).attr('code');
                    if (_field != "" && _field != undefined) {
                        var data = DataRow[_field];
                    }
                    switch (_ftype) {
                        case 'integer':
                            if (data == "undefined" || data == null || data == "") data = "0";
                            data = number_format(data);
                            $(this).find("input:first").val(data).attr("oldvalue", data);
                            break;
                        case 'string':
                            if (data == "undefined" || data == null || data == "") data = "";
                            $(this).find("input:first").val(data).attr("oldvalue", data);
                            break;
                        case 'combo':
                            if (data == "undefined" || data == null || data == "") data = "";
                            $(this).find("select:first").val(data).attr("oldvalue", data);
                            break;
                        default:
                            if (data == "undefined" || data == null || data == "") data = "&nbsp;";
                            $(this).html(data)
                    }
                });

                newTr.find('td:eq(1)').html((rowNum * 1.0 * (VIEWPAGE - 1)) + i + 1);
                newTr.find('td:eq(2)').html('R');
                $(this).find('tbody').append(newTr);
            }

            if (JsonForm.rowspan) {
                var colCount = JsonForm.colModel.length;
                for (var i = 0; i < colCount; i++) {
                    if (JsonForm.colModel[i].rowspan) _datatable.rowspan(i + 3);
                }
            }


            /* page dispplay  --------------------------------------------------- */

            var ViewNum = "<ul class='icons ui-widget ui-helper-clearfix'>";

            if (JsonForm.ShowPageNum) {
                var StartPagenum = parseInt((VIEWPAGE - 1) / 10) * 10;
                ViewNum += "<li class='pgNum ui-state-default ui-corner-all' pgnum='1'><span class='ui-icon ui-icon-seek-first'></span></li>";
                ViewNum += "<li class='pgNum ui-state-default ui-corner-all' pgnum='" + (StartPagenum > 10 ? StartPagenum : 1) + "'><span class='ui-icon ui-icon-seek-prev'></span></li>";
                for (i = StartPagenum + 1; i < TPCOUNT * 1 + 1 && i < (StartPagenum * 1 + 11); i++) {
                    if (VIEWPAGE * 1 == i) { ViewNum += "<li class='pgNum pgNumNow' pgnum='" + i + "'>&nbsp;" + i + "&nbsp;</li>"; }
                    else { ViewNum += "<li class='pgNum ui-state-default ui-corner-all' pgnum='" + i + "'>&nbsp;" + i + "&nbsp;</li>"; }
                }
                ViewNum += "<li class='pgNum ui-state-default ui-corner-all' pgnum='" + (i < TPCOUNT * 1 + 1 ? StartPagenum + 11 : TPCOUNT) + "'><span class='ui-icon ui-icon-seek-next'></span></li>";
                ViewNum += "<li class='pgNum ui-state-default ui-corner-all' pgnum='" + (StartPagenum + 2 < TPCOUNT ? StartPagenum + 2 : TPCOUNT) + "'><span class='ui-icon ui-icon-seek-next'></span></li>";
            }
            else {
                ViewNum += "<li class='pgNum ui-state-default ui-corner-all' pgnum='1'><span class='ui-icon ui-icon-seek-first'></span></li>";
                ViewNum += "<li class='pgNum ui-state-default ui-corner-all' pgnum='" + (VIEWPAGE > 1 ? VIEWPAGE - 1 : 1) + "'><span class='ui-icon ui-icon-seek-prev'></span></li>";
                ViewNum += "<li class='pgNum pgNumNow' pgnum='" + VIEWPAGE + "'>&nbsp;" + VIEWPAGE + "&nbsp;:&nbsp;Page</li>";
                ViewNum += "<li class='pgNum ui-state-default ui-corner-all' pgnum='" + (VIEWPAGE * 1.0 < TPCOUNT * 1.0 ? VIEWPAGE * 1.0 + 1 : TPCOUNT) + "'><span class='ui-icon ui-icon-seek-next'></span></li>";
                ViewNum += "<li class='pgNum ui-state-default ui-corner-all' pgnum='" + TPCOUNT + "'><span class='ui-icon ui-icon-seek-end'></span></li>";
            }


            // ViewNum += "<li class=''> &nbsp;&nbsp;" + TRCOUNT + " : Records</li>";
            ViewNum += "</ul>";

            $(this).find('.head .SuperTable_head_R').html("<div class='PgnumArea'>" + ViewNum + "</div>");
            $(this).find('.foot .SuperTable_head_R').html("<div class='PgnumArea'>" + ViewNum + "</div>");

            if (!JsonForm.ShowPageMove) {
                $(this).find('.head .SuperTable_head_R').hide();
                $(this).find('.foot .SuperTable_head_R').hide();
            }


            $(this).find('.pgNum').hover(
				function () { $(this).addClass('ui-state-hover'); },
				function () { $(this).removeClass('ui-state-hover'); }
			);

            //            var jobCount = JsonForm.Jobs.length;
            //            /// : 초기테이블 해드와 row를 생성한다 ////////////////////////////////////////////
            //            var jobComm = "<ul class='leftMenu'>";
            //            for (var i = 0; i < jobCount; i++) {
            //                var _index = JsonForm.Jobs[i].index;
            //                var _name = JsonForm.Jobs[i].name;
            //                jobComm += "<li class='pgJob' index='" + _index + "'><span>" + _name + "</span></li>";

            //            }
            //            jobComm += "</ul>";
            //            $(this).find('.head .SuperTable_head_L').html("<div class='PgJobArea'>" + jobComm + "</div>");

            var SortField = JsonForm.Orderby.split(' ');

            $(this).find('thead td').removeClass('SuperTable_SortAsc').removeClass('SuperTable_Sortdesc');
            _obj = $(this).find('thead td[field="' + SortField[0] + '"]');
            var _sortclass = (SortField[1] == "ASC" ? "SuperTable_SortAsc" : "SuperTable_Sortdesc");
            _obj.addClass(_sortclass);
            $(this).data("VIEWPAGE", VIEWPAGE);
            this.SuperTable("BindAction");
            return Rows;
        },

        BindAction: function () {
            var _obj = $(this);
            var JsonForm = $(this).data("formatData");
            //var Foot = $(this).data("Foot");
            var _datatable = $('tbody', this);
            _datatable.find('tr').mouseover(function () { $(this).addClass("ui-state-hover") }).mouseout(function () { $(this).removeClass("ui-state-hover") });
            _datatable.find('tr').bind("click", function (e) {
                $(this).parent().find('tr').removeClass('ui-state-active'); // 행클릭시 모든행의 색상을 white
                $(this).addClass('ui-state-active'); 					// 행클릭시 선택된 행 색상.
                // 향후 체크박스가 아닌 클릭이벤트동작시에 적용하기로 함
                if (e.ctrlKey) {    //Ctrl+Click  
                    //  $(this).addClass('SuperTable_tbody_tr_checked')						// 행클릭시 선택된 행 색상.
                    //  $(this).find('td:eq(0)').find('input').attr("checked", "checked");
                };
            });



            $(this).find('thead td').unbind("click").bind("click", function (e) {
                // 테이블 해드클릭시 정렬시키는 루틴
                if (this.cellIndex == 0) {
                    if ($(this).find('.ChkAll:checkbox:checked').val() == 'checkAll') {
                        _datatable.find('tr').find('> td:first').find('input:checkbox').attr("checked", "checked");
                        _datatable.find('tr td').addClass('SuperTable_select_tr');
                    }
                    else {
                        _datatable.find('tr').find('> td:first').find('input:checkbox').attr("checked", "");
                        _datatable.find('tr td').removeClass('SuperTable_select_tr');
                    }

                    _chkCnt = _datatable.find('tr').find('> td:first').find('input:checked').length;
                    //Foot.find('td:eq(1)').html(_chkCnt + ' Selected');

                    return;
                }
                _field = $(this).attr('field');
                if (_field != undefined) {
                    if (JsonForm.Sort == true) _obj.SuperTable("SortPage", $(this).attr('field'));
                }
            });

            $(this).find('.pgNum').mouseover(function () { $(this).addClass("pgNumOver") }).mouseout(function () { $(this).removeClass("pgNumOver") });

            $(this).find('.pgNum').unbind("click").bind("click", function (e) {
                _obj.SuperTable("ShowPage", $(this).attr('pgnum'));
            });


            // 외부 콜백 함수를 호출한다.
            _datatable.find('tr').bind("click", eval(JsonForm.trClick));
            //            _datatable.find('td').bind("dblclick", eval(JsonForm.tdDblClick));
            _datatable.find('td').unbind("mouseover").bind("mouseover", JsonForm.tdMouseover);
            _datatable.find('td').change(JsonForm.tdChange);

            _datatable.find('td').bind("dblclick", function (e) {
                if (JsonForm.CellEditUrl == "" || JsonForm.CellEditUrl == undefined) return;
                var _td = $(this);
                var _objDiv = _td.parent().parent().parent().parent();
                var OldValue = _td.html() == '&nbsp;' ? '' : _td.text();

                $('#CommonDailog').html("수정할 내용은?<p /><input id='showCustDialog_txt' type='text' value='" + OldValue + "' /> ");
                $('#CommonDailog').dialog({ autoOpen: false, width: 400, height: 200, modal: true, closeOnEscape: false,
                    title: '자료수정',
                    buttons: {
                        "확인": function () {
                            var NewValue = jQuery.trim($('#showCustDialog_txt').val());

                            _objDiv.SuperTable("CellEditUrl", _td, NewValue);
                            $(this).dialog("close");

                        },
                        "취소": function () {
                            $(this).dialog("close");
                        }
                    }

                });
                $('#CommonDailog').dialog('open');

            });


        },

        // 검색결과가 1건인 경우 바로 GridClick 이벤트를 실행함. 2011/02/13 by 최보현
        AddRow: function () {
            var TrData = $(this).data("TRdata").clone();
            var _datatable = $(this).data("DataBody")
            TrData.find('td:eq(2)').html("C");
            _datatable.find('> tbody').append(TrData);
            this.SuperTable("BindAction");
        },

        DeleteRow: function () {
            var _datatable = $(this).data("DataBody")

            _datatable.find('tr').find('> td:first').find('input:checked').each(function (index) {
                var TrData = $(this).parent().parent();
                var _CRUD = TrData.find('td:eq(2)').html();
                if (_CRUD == "C") { TrData.remove(); }
                if (_CRUD == "R" || _CRUD == "U") { TrData.find('td:eq(2)').html("D"); TrData.hide() }
                if (_CRUD == "D") { TrData.find('td:eq(2)').html("R"); }
            });
        },


        CellEditUrl: function (_cell, NewValue) {


            var key = _cell.parent().attr("key");
            var field = _cell.attr("field");
            var OldValue = _cell.html() == '&nbsp;' ? '' : _cell.text();
            if (OldValue == NewValue) return;

            var JsonForm = $(this).data("formatData");
            var pl = new JSONClientParameters();
            pl.add("key", key);
            pl.add("field", field);
            pl.add("OldValue", OldValue);
            pl.add("NewValue", NewValue);
            var _Obj = $(this);
            PostJsonData(JsonForm.CellEditUrl, pl, function (data) {
                _cell.html(NewValue);
            });
        },

        Refresh: function () {
            var VIEWPAGE = $(this).data("VIEWPAGE");
            this.SuperTable("ShowPage", VIEWPAGE);


        },

        ClearData: function () {
            $(this).find('tbody tr').remove();

        },

        // * -- 선택된 row의 필드만 배열로 출력해준다 *//
        GetSelectKey: function () {
            var Keys = new Array();
            $(this).find('.body tr').find('> td:first').find('input:checked').each(function (index) {
                var _tr = $(this).parent().parent();
                var _key = _tr.attr('key');
                Keys[Keys.length] = _key;
            });

            return Keys;

        },

        GetValue: function (key, index, data) {
            var _tr = $(this).find('.body tr[key="' + key + '"]');
            var _td = _tr.find('td[field="' + index + '"]');
            return _td.html();

        },

        SetValue: function (key, index, data) {
            var _tr = $(this).find('.body tr[key="' + key + '"]');
            var _td = _tr.find('td[field="' + index + '"]');
            _td.html(data);
        },

        GetData: function (JsonData) {
            var RetXml = "<?xml version='1.0' encoding='utf-8' ?><DataTable>";
            $(this).find('.body tr').find('> td:first').find('input:checked').each(function (index) {
                var _tr = $(this).parent().parent();
                var _CRUD = _tr.find('td:eq(2)').html();
                var _key = _tr.attr('key');
                if (_CRUD == 'R') return true;
                if (_CRUD == 'C') _key = 0;
                RetXml += "<Record>";
                RetXml += String.format("<_KEY>{1}</_KEY><_CRUD>{0}</_CRUD>", _CRUD, _key);
                if (_CRUD == 'D') {
                    RetXml += "</Record>";
                    return true;
                }
                var _CRUDFIELD = "";
                _tr.find('td').each(function (index) {
                    var field = $(this).attr("field");
                    if (field == undefined) return true;
                    // 만일 변경된 TD가 아니면 continue
                    if ($(this).hasClass("changeTD")) {
                        _CRUDFIELD += "," + field;
                    }
                    else {
                        return true;
                    }

                    switch ($(this).attr("ftype")) {
                        case 'integer':
                            RetXml += String.format("<{0}>{1}</{0}>", field, $(this).find('> input').val());
                            break;
                        case 'string':
                            RetXml += String.format("<{0}>{1}</{0}>", field, $(this).find('> input').val());
                            break;
                        case 'combo':
                            RetXml += String.format("<{0}>{1}</{0}>", field, $(this).find('> select').val());
                            break;
                        default:
                            RetXml += String.format("<{0}>{1}</{0}>", field, $(this).html());
                    }
                });

                RetXml += "<_CRUDFIELD>" + _CRUDFIELD + "</_CRUDFIELD>";

                RetXml += "</Record>"
            });

            RetXml += "</DataTable>"

            return RetXml;
        },

        GetRowCount: function (options) {
            alert(options + "-" + "옵션입니다");
            return this;

        }
    };
})(jQuery);


(function($){ 
$.fn.rowspan  = function (colIdx) {
    return this.each(function () {

        var that;
        $('tr', this).each(function (row) {
           $('td:eq('+colIdx+')', this).each(function(col) {
                if ($(this).html() == $(that).html()) {
                    rowspan = $(that).attr("rowSpan");
                    if (rowspan == undefined) {
                        $(that).attr("rowSpan", 1);
                        rowspan = $(that).attr("rowSpan");
                    }
                    rowspan = Number(rowspan) + 1;
                    $(that).attr("rowSpan", rowspan); // do your action for the colspan cell here
                    $(this).hide(); // .remove(); // do your action for the old cell here
                } else {
                    that = this;
                }
                that = (that == null) ? this : that; // set the that if not already set
            });
        });

    });
};
})(jQuery);
